// 导入外部模块
const { customRequire } = require('./utils.js');
const { Page } = customRequire('playwright');

class FirstPage {
    constructor(page) {
        this.page = page;
    }

    subcontractListEntry() {
        this.page.getByRole('link', { name: 'SubContract' }).click();
        this.page.getByRole('link', { name: 'SubContract List' }).click();
    }

    async orderListEntry() {
        try {
            await this.page.getByRole('link', { name: 'Order' }).click();
            await this.page.getByRole('link', { name: 'Order List', exact: true }).click();
        } catch (error) {
            // 网络连接错误处理
            if (error.message.includes('net::ERR_NAME_NOT_RESOLVED')) {
                throw new Error('网络连接失败：无法解析域名，请连接SGS VPN后重试');
            } else if (error.message.includes('net::ERR_INTERNET_DISCONNECTED')) {
                throw new Error('网络连接失败：网络已断开，请检查网络连接后重试');
            } else if (error.message.includes('net::ERR_CONNECTION_TIMED_OUT')) {
                throw new Error('网络连接失败：连接超时，请检查网络连接或稍后重试');
            } else {
                throw new Error(`导航到订单列表失败: ${error.message}`);
            }
        }
    }

    reportListEntry() {
        this.page.click('li.dropdown > a.dropdown-toggle:has-text("Report")');
        // this.page.getByRole('link', { name: 'Report' }).click();
        this.page.getByRole('link', { name: 'Report List', exact: true }).click();
    }
}

module.exports = {
    FirstPage
};
